package com.kun.companion.core.ui.tree;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Node;
import javafx.scene.control.TreeItem;

/**
 * 增强型树节点基类
 *
 * @param <T> 节点数据类型
 */
public class BaseTreeItem<T> extends TreeItem<T> {
    /**
     * 节点元数据
     */
    protected final ObjectProperty<Node> nodeIcon = new SimpleObjectProperty<>();
    protected final BooleanProperty loaded = new SimpleBooleanProperty(false);

    public ObjectProperty<Node> getNodeIcon() {
        return this.nodeIcon;
    }

    public BaseTreeItem() {
        this(null);
    }

    public BaseTreeItem(T value) {
        this(value, null);
    }

    public BaseTreeItem(T value, Node graphic) {
        super(value, graphic);
    }

    /**
     * 延迟加载子节点实现
     */
    protected void lazyLoadChildren() {
        // 供子类实现具体加载逻辑
    }

    /**
     * 节点图标绑定属性
     */
    public ObjectProperty<Node> nodeIconProperty() {
        return nodeIcon;
    }

    /**
     * 标记节点是否已加载完成
     */
    public BooleanProperty loadedProperty() {
        return loaded;
    }
}
